package com.gb.push.handler;

import com.gb.push.param.SendRequest;
import com.gb.push.service.PushSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: wgs
 * @Date 2022/1/21 13:50
 * @Classname SenderActivity
 * @Description 策略
 */
@Service
@Slf4j
public class SenderActivity {

    private static final Map<PushSender.PushSenderEnum, PushSender> PUSH_SENDER_MAP = new ConcurrentHashMap<PushSender.PushSenderEnum, PushSender>();


    /**
     * 构造器注入 代替工厂模式
     */
    public SenderActivity(List<PushSender> pushSenders) {
        for (PushSender pushSender : pushSenders) {
            PUSH_SENDER_MAP.put(pushSender.getPushSenderEnum(), pushSender);
        }
    }

    public void singleMsg(PushSender.PushSenderEnum pushSenderEnum, SendRequest sendRequest) {
        PushSender pushSender = PUSH_SENDER_MAP.get(pushSenderEnum);
        pushSender.singleMsg(sendRequest);
    }


}
